package com.zmj.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zmj.entity.User;
import com.zmj.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RequestMapping("/system")
@RestController
public class UserController {

    //@Autowired
    //private RedisTemplate redisTemplate;

    @RequestMapping(value = "/login")
    public String login(User user){
        System.out.println(JSON.toJSONString(user));
        if("admin".equals(user.getUsername())){
            user.setId("1001");
            String access_token = JwtUtils.getToken(user);
            //redisTemplate.boundValueOps("access_token").set(access_token,10, TimeUnit.MINUTES);
            return access_token;
        }
        return "error";
    }

    @RequestMapping(value = "/list")
    public String list(){
        System.out.println("usercontroer list-------");
        return "hello";
    }
}
